define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {


    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'information/led/index' + location.search,
                    del_url: 'information/led/del',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                singleSelect:false,
                fixedColumns: true,
                fixedRightNumber: 1,
                showExport: false,
                showToggle:false,
                //showFullscreen:true,
                //striped:true,
                //remember: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title:__('Id'), operate: false,visible:false},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'shelves_name', title: __('Shelves_name'), operate: 'LIKE'},
                        {field: 'position', title: __('Position'), operate: 'LIKE'},
                        {field: 'color', title: __('Color'), operate: 'LIKE'},
                        
                        {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
                        {field: 'during', title: __('During'), operate: false},
                        
                        {field: 'output', title: __('Output'), searchList: {"ON":__('ON')," 2":__('OFF')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}
                    ]
                ]
            });
         // 为表格绑定事件
            Table.api.bindevent(table);
            
            $(table).data("operate-del", null);
        },

        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            //获取选中的行
            selectedids: function (table, current) {
                var options = table.bootstrapTable('getOptions');
                //如果有设置翻页记忆模式
                if (!current && options.maintainSelected) {
                    return options.selectedIds;
                }
                return $.map(table.bootstrapTable('getSelections'), function (row) {
                    return row[options.pk];
                });
            },

            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
